/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.moviedownloader.DbModel;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 *
 * @author martin
 */
public class Movie{

    private List<Title> names = new ArrayList<>();
    private Origin origin;
    private int rating;
    private Integer csfdId;
    private Long id;

    private String reducedName;
    private String originalName;
    private Format format;

    private List<Genre> genres = new ArrayList<>();
    private Set<Person> cast = new HashSet<>();
    

    public Format getMovieFormat() {
        return format;
    }

    public void setFormat(Format movieType) {
        this.format = movieType;
    }

    public String getOriginalName() {
        return originalName;
    }

    public void setOriginalName(String orriginalName) {
        this.originalName = orriginalName;
    }

    public String getReducedName() {
        return reducedName;
    }

    public void setReducedName(String reducedName) {
        this.reducedName = reducedName;
    }

    public Integer getCsfdId() {
        return csfdId;
    }

    public int getRating() {
        return rating;
    }

    public void setRating(int rating) {
        this.rating = rating;
    }

    public void setCsfdId(int csfdId) {
        this.csfdId = csfdId;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<Title> getNames() {
        return Collections.unmodifiableList(names);
    }

    public void setNames(List<Title> names) {
        this.names = names;
    }

    public void setGenres(List<Genre> genre) {
        this.genres = genre;
    }

    public void setCast(List<Person> cast) {
        for (Person person : cast) {
            if(!this.cast.contains(person)){
                this.cast.add(person);
            }
        }
    }

    public Origin getOrigin() {
        return origin;
    }

    public void setOrigin(Origin origin) {
        this.origin = origin;
    }

    public List<Genre> getGenres() {
        return Collections.unmodifiableList(genres);
    }

    public Set<Person> getCast() {
        return Collections.unmodifiableSet(cast);
    }

    public static int parseCsfdId(String moviePageAdress) {
        Objects.requireNonNull(moviePageAdress);
        return Integer.parseInt(
                moviePageAdress.split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)")[1]);
    }

    @Override
    public String toString() {
        return "Movie{" + "names=" + names + ", origin=" + origin + ", rating=" + rating + ", csfdId=" + csfdId + ", id=" + id + ", reducedName=" + reducedName + ", originalName=" + originalName + ", movieType=" + format + ", genre=" + genres + ", cast=" + cast + '}';
    }

    
    public Movie fromString(String line) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

}
